﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace fileinspector
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            DialogResult ds = openFileDialog1.ShowDialog();

            if (ds == DialogResult.OK)
            {
                tbFile.Text = openFileDialog1.InitialDirectory + openFileDialog1.FileName;
                Analyse();
            }
        }

        private void btnAnalyse_Click(object sender, EventArgs e)
        {
            Analyse();
        }

        private void Analyse()
        {
            tbResult.Text = "";
            string filePath = tbFile.Text;
            if (!File.Exists(filePath))
            {
                tbResult.Text += "File not exist!\r\n";
            }


            tbResult.Text += "File: " + Path.GetFileName(filePath) + "\r\n";

            if (filePath.ToLower().EndsWith(".dll"))
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(filePath);

                    Type[] types = assembly.GetExportedTypes();
                    foreach (Type type in types)
                    {
                        tbResult.Text += "Namespace: " + type.Namespace + "\r\n";
                        tbResult.Text += "Type name: " + type.Name + "\r\n";
                        tbResult.Text += "Assembly Qualified Name: " + type.AssemblyQualifiedName + "\r\n";
                        break;
                    }
                }
                catch(Exception ex)
                {
                    tbResult.Text += "Cannot load DLL assembly: " + ex.ToString();
                }
            }
        }
    }
}
